// 
//  Copyright (C) 2009 Jacek Trubłajewicz
// 
//  This program is free software; you can redistribute it and/or modify
//  it under the terms of the GNU General Public License as published by
//  the Free Software Foundation; either version 2 of the License, or
//  (at your option) any later version.
// 
//  This program is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
//  GNU General Public License for more details.
//  
//  You should have received a copy of the GNU General Public License
//  along with this program; if not, write to the Free Software
//  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
// 

using System;
using System.Drawing;
using System.IO;
using Mono.Unix;
using NLog;

namespace wxGadu
{
	
	/// <summary>
	/// Entry field for <c>ChatFrame</c> which allow to use
	/// shift+enter combination without processing 
	/// <c>EVT_TEXT_ENTER</c> event
	/// </summary>
	public class MessageEntryTextCtrl : wx.TextCtrl
	{
		/// <summary>
		/// Ctor
		/// </summary>
		/// <param name="parent">
		/// A <see cref="wx.Window"/>
		/// </param>
		/// <param name="id">
		/// A <see cref="System.Int32"/>
		/// </param>
		/// <param name="val">
		/// A <see cref="System.String"/>
		/// </param>
		/// <param name="pos">
		/// A <see cref="Point"/>
		/// </param>
		/// <param name="size">
		/// A <see cref="Size"/>
		/// </param>
		/// <param name="style">
		/// A <see cref="System.UInt32"/>
		/// </param>
		public MessageEntryTextCtrl(wx.Window parent, int id, string val, Point pos, Size size, uint style):
			base(parent, id, val, pos, size, style)
		{
			EVT_KEY_DOWN(new wx.EventListener(OnKeyDown));
		}
		
		protected void OnKeyDown(object sender, wx.Event evt)
		{
			wx.KeyEvent keyEvt = (wx.KeyEvent) evt;
			
			if (keyEvt.KeyCode == (int) wx.KeyCode.WXK_RETURN)
			{
				if (keyEvt.ShiftDown)
					this.AppendText(Environment.NewLine);
				else
					evt.Skip();
			}
			else
				keyEvt.Skip();
		}
	}
}
